/* 封装axios用于发送请求 */
import axios from 'axios'
import store from '@/store'

// 创建一个新的axios实例
const request = axios.create({
  baseURL: 'http://likede2-admin.itheima.net/likede/',
  timeout: 5000
})

// 添加请求拦截器
request.interceptors.request.use(config => {
  // console.log(store.state.user.token)
  config.headers.Authorization = `${store.state.user.token}`
  return config
}, error => {
  return Promise.reject(error)
})

// 添加响应拦截器
request.interceptors.response.use(response => {
  return response.data
}, error => {
  return Promise.reject(error)
})

export default request
